import { createStore, applyMiddleware } from 'redux'
// import logger from 'redux-logger'
import thunk from 'redux-thunk'

// applyMiddleware  中间件(让redux中可以执行异步代码) 

// 纯函数
let reducer = (state, action) => {
    let NewState = JSON.parse(JSON.stringify(state))
    switch(action.type) {
        case 'ADD_COUNT':
            NewState.count += action.count
            return NewState
        case 'SET_DATA':
            NewState.data = action.list
            return NewState
    }
    return NewState
}

// axios
let initState = {
    count: 100,
    num: 999999,
    data: []
}

let store = createStore(reducer, initState, applyMiddleware(thunk))
// applyMiddleware(thunk)

// 使用redux-thunk  修改了dispatch函数(增强dispatch函数)
// dispatch({ type: "ADD" })

// 原来的dispatch    最新的dispatch(超级dispatch)

window.store = store

export default store

